<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../css/oksub.css">
	<script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
	<style type="text/css">
	
	</style>
</head>
<body>
<div class="ok-body">
	
	
	<table class="layui-hide" id="tableId" lay-filter="tableFilter" ></table>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/okform.js"></script>
<script>
     
    var ID = request("ID"); 
    var ManagerId = "";
    
    function AcceptClick() {
    	layui.use([ "okUtils"], function () {
    		let okUtils = layui.okUtils;
    		let $ = layui.jquery;
    		var saveCondition = {};
    		saveCondition['ID'] = ID;
    		saveCondition['FUNDSID']  = $("#FUNDSID").val();
    		saveCondition['FullName'] =encodeURI($("#FullName").val().trim());
    		saveCondition['SortCode'] = $("#SortCode").val();
    		saveCondition['ITEMID'] = $("#ITEMID").val();
    		var searchcondition = JSON.stringify(saveCondition)
    		
    		okUtils.ajax("SharesFundsServlet?method=save", "get", {searchcondition: searchcondition}, true).done(function (response) {
				   console.log(response);
				  
				}).fail(function (error) {
					console.log(error)
				});
    	})
    
    }
    
    
	layui.use(["element", "form","jquery", "table",  "okLayer", "okUtils"], function () {
		let form = layui.form;		
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		let table = layui.table;		
		let $ = layui.jquery;
		okLoading.close();		
		let stable = table.render({
			elem: '#tableId',
			url: "../../SharesFundsServlet?method=getSharesData",
			size: "sm",
			page: false,
			defaultToolbar: false,			
			toolbar: "#toolbarTpl",	
			where:{FUNDSID:ID},
			cols: [[
				{title: "ID", type :"numbers", width: 100},			
				{field: "sharesid", title: "sharesid", width: 100},	
				{field: "name", title: "股票名字", width: 100},	
				{field: "price", title: "当前价格", width: 100},	
				{field: "todayOpen", title: "今日开盘价", width: 100},
				{field: "yesterdayClose", title: "昨日收盘价", width: 100},			
				{title: "操作", width: 100, align: "center", fixed: "right", templet: function(d){				    
				    if(d.isAdd == 0){
				        return '<a href="javascript:" title="添加" lay-event="add"><i class="layui-icon">&#xe624;</i></a>	';  
				    }else if(d.isAdd == 1){
				        return '<a href="javascript:" title="剔除" lay-event="del"><i class="layui-icon">&#xe67e;</i></a>	';  
				    }
				}}
			]],
			done: function (res, curr, count) {
				console.info(res, curr, count);
			}
		});
		
		table.on("tool(tableFilter)", function (obj) {
			let data = obj.data;
			switch (obj.event) {
				case "add":
				    add(data);
					break;
				case "del":
					del(data);
					break;
			}
		});
		
		function add(data) {		    
		    var saveCondition = {};
    		saveCondition['FUNDSID'] = ID;    	
    		saveCondition['FullName'] =encodeURI(data.name);
    		saveCondition['SHAREID'] =data.sharesid;    		
    		var searchcondition = JSON.stringify(saveCondition)
			okUtils.ajax("SharesServlet?method=save", "get", {searchcondition:searchcondition}, true).done(function (response) {
			       stable.reload();
				}).fail(function (error) {
				    $("#FullName").val("");
					console.log(error)
				   
			});	
		}

		function del(data) {		
			okUtils.ajax("SharesServlet?method=delete", "get", {sharesid:data.sharesid}, true).done(function (response) {
			       stable.reload();
				}).fail(function (error) {
				    $("#FullName").val("");
					console.log(error)
				   
			});
		  
		}
		
	});
</script>

</body>
</html>
